package June;
import java.util.Scanner;
public class Test_19_5 {
    public static void main(String[] args) {
//        System.out.println((int)(Math.random() * 3));
        Scanner myScanner = new Scanner(System.in);
        guessquan g = new guessquan();
        int input = 0;
        windows w = new windows();
        do {
            w.window();
            System.out.println("请输入你的选择：");
            input = myScanner.nextInt();
            if (input == 1) {
                System.out.println("游戏开始！");
                g.play();
            } else {
                System.out.println("退出游戏！");
                break;
            }


        } while(true);
    }
}

class windows {
    public void window() {
        System.out.println("************");
        System.out.println("***1.play***");
        System.out.println("***0.exit***");
        System.out.println("************");
    }
}
// 有个人 Tom 设计他的成员变量.
// 成员方法, 可以电脑猜拳,
// 电脑每次都会随机生成 0，1.2
// 0 表示 石头
// 1 表示 剪刀
// 2 表示 布
// 并要可以显示 Tom的输赢次数(清单)
class guessquan {
    public void play() {
        System.out.print("请出拳(输入石头、剪刀、布):");
        String quan1;
        int tmp = (int)(Math.random() * 3);
        if (tmp == 0) {
            quan1 = "石头";
        } else if (tmp == 1) {
            quan1 = "剪刀";
        } else {
            quan1 = "布";
        }
        Scanner myScanner = new Scanner(System.in);
        String input = myScanner.next();
        int index = -1;
        switch (input) {
            case "石头" -> index = 0;
            case "剪刀" -> index = 1;
            case "布" -> index = 2;
            default -> System.out.println("你的输入有误！");
        }
        if (tmp == 0 && index == 0) {
            System.out.println("电脑出的拳是：" + quan1 + "\n" +"玩家出的拳是：" + input);
            System.out.println("结果是平局");
        }
        if (tmp == 0 && index == 1) {
            System.out.println("电脑出的拳是：" + quan1 + "\n" +"玩家出的拳是：" + input);
            System.out.println("结果是电脑赢");
        }
        if (tmp == 0 && index == 2) {
            System.out.println("电脑出的拳是：" + quan1 + "\n" +"玩家出的拳是：" + input);
            System.out.println("结果是玩家赢");
        }
        if (tmp == 1 && index == 1) {
            System.out.println("电脑出的拳是：" + quan1 + "\n" +"玩家出的拳是：" + input);
            System.out.println("结果是平局");
        }
        if (tmp == 1 && index == 2) {
            System.out.println("电脑出的拳是：" + quan1 + "\n" +"玩家出的拳是：" + input);
            System.out.println("结果是电脑赢");
        }
        if (tmp == 1 && index == 0) {
            System.out.println("电脑出的拳是：" + quan1 + "\n" +"玩家出的拳是：" + input);
            System.out.println("结果是玩家赢");
        }
        if (tmp == 2 && index == 2) {
            System.out.println("电脑出的拳是：" + quan1 + "\n" +"玩家出的拳是：" + input);
            System.out.println("结果是平局");
        }
        if (tmp == 2 && index == 1) {
            System.out.println("电脑出的拳是：" + quan1 + "\n" +"玩家出的拳是：" + input);
            System.out.println("结果是电脑赢");
        }
        if (tmp == 2 && index == 0) {
            System.out.println("电脑出的拳是：" + quan1 + "\n" +"玩家出的拳是：" + input);
            System.out.println("结果是玩家赢");
        }
    }
}